package com.study_security.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.study_security.dto.MemberDTO;
import com.study_security.dto.ProjectDTO;
import com.study_security.dto.TaskDTO;
import com.study_security.entity.Task;
import com.study_security.mapper.TaskMapper;
import com.study_security.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements TaskService {
    @Autowired
    private TaskMapper taskMapper;

    @Override
    public List<TaskDTO> getTasksByProjectName(String projectName) {
        return taskMapper.selectTasksByProjectName(projectName);
    }
    @Override
    public List<TaskDTO> getTasksByProjectId(Long projectId) {
        return taskMapper.selectTasksByProjectId(projectId);
    }

    @Override
    public List<ProjectDTO> selectUserProjects(Long userId) {
        return taskMapper.selectUserProjects(userId);
    }

    @Override
    public boolean addTask(Task task) {
        int result = taskMapper.insertTask(task);
        return result > 0;
    }

    @Override
    public boolean updateTaskStatus(Long taskId) {
        int result = taskMapper.updateTaskStatus(taskId);
        return result > 0;
    }

    @Override
    public List<MemberDTO> getProjectMembers(Long projectId) {
        return taskMapper.selectProjectMembers(projectId);
    }

    @Override
    public boolean deleteTask(Long taskId) {
        int result = taskMapper.deleteTask(taskId);
        return result > 0;
    }

    @Override
    public boolean taskIdUserIdExisits(Long taskId, Long userId) {
        return taskMapper.countByTaskIdUserId(taskId,userId)==0;
    }

}
